package com.hashMapDemo;

import java.util.HashMap;
import java.util.Random;

/**
 * @author sea_son
 * @date 2018/7/19 21:32
 * 海客森：www.hikson.com
 * QQ：1099161566@qq.com
 * 1.
 */
public class HashMapDemo {
    public static final HashMap<String, String> map = new HashMap<String, String>();
    private static Long timeTemp = System.currentTimeMillis()+500L;

    public static void main(String[] args) throws InterruptedException {
        //线程1
        for (int i = 0; i < 2; i++) {
            new MyThread(map,timeTemp).start();
        }
        Thread.currentThread().sleep(1000);

        for (String key : map.keySet()) {
            if (!key.equals(map.get(key))) {
                System.out.println(key + "——" + map.get(key));
            }
        }
    }
}

class MyThread extends Thread {
    public MyThread(HashMap<String, String> map,Long timeTemp) {
        this.map = map;
        this.timeTemp = timeTemp;
    }

    HashMap<String, String> map;
    Long timeTemp;

    @Override
    public void run() {
        for (int i = 0; i < 25; i++) {
            if (i == 11) {
                while (System.currentTimeMillis() <= timeTemp) {
                }
            }
            int anInt = new Random().nextInt(25);
            map.put(String.valueOf(i), String.valueOf(i));
        }
    }
}